home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / Dimension.java < prev    next >
Text File  |  1998-09-22  |  5KB  |  155 lines

  1. /*
  2.  * @(#)Dimension.java    1.14 98/07/01
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14. package java.awt;
  15.  
  16. /**
  17.  * The <code>Dimension</code> class encapsulates the width and 
  18.  * height of a component in a single object. The class is 
  19.  * associated with certain properties of components. Several methods 
  20.  * defined by the <code>Component</code> class and the 
  21.  * <code>LayoutManager</code> interface return a 
  22.  * <code>Dimension</code> object. 
  23.  * <p>
  24.  * Normally the values of <code>width</code> 
  25.  * and <code>height</code> are non-negative integers. 
  26.  * The constructors that allow you to create a dimension do 
  27.  * not prevent you from setting a negative value for these properties. 
  28.  * If the value of <code>width</code> or <code>height</code> is 
  29.  * negative, the behavior of some methods defined by other objects is 
  30.  * undefined. 
  31.  * 
  32.  * @version     1.14, 07/01/98
  33.  * @author     Sami Shaio
  34.  * @author     Arthur van Hoff
  35.  * @see         java.awt.Component
  36.  * @see         java.awt.LayoutManager
  37.  * @since       JDK1.0
  38.  */
  39. public class Dimension implements java.io.Serializable {
  40.     
  41.     /**
  42.      * The width dimension.
  43.      */
  44.     public int width;
  45.  
  46.     /**
  47.      * The height dimension.
  48.      */
  49.     public int height;
  50.  
  51.     /*
  52.      * JDK 1.1 serialVersionUID 
  53.      */
  54.      private static final long serialVersionUID = 4723952579491349524L;
  55.  
  56.     /** 
  57.      * Creates an instance of <code>Dimension</code> with a width 
  58.      * of zero and a height of zero. 
  59.      * @since   JDK1.0
  60.      */
  61.     public Dimension() {
  62.     this(0, 0);
  63.     }
  64.  
  65.     /** 
  66.      * Creates an instance of <code>Dimension</code> whose width  
  67.      * and height are the same as for the specified dimension. 
  68.      * @param    d   the specified dimension for the 
  69.      *               <code>width</code> and 
  70.      *               <code>height</code> values.
  71.      * @since    JDK1.0
  72.      */
  73.     public Dimension(Dimension d) {
  74.     this(d.width, d.height);
  75.     }
  76.  
  77.     /** 
  78.      * Constructs a Dimension and initializes it to the specified width and
  79.      * specified height.
  80.      * @param width the specified width dimension
  81.      * @param height the specified height dimension
  82.      * @since JDK1.0
  83.      */
  84.     public Dimension(int width, int height) {
  85.     this.width = width;
  86.     this.height = height;
  87.     }
  88.  
  89.     /**
  90.      * Gets the size of this <code>Dimension</code> object.
  91.      * This method is included for completeness, to parallel the
  92.      * <code>getSize</code> method defined by <code>Component</code>.
  93.      * @return   the size of this dimension, a new instance of 
  94.      *           <code>Dimension</code> with the same width and height.
  95.      * @see      java.awt.Dimension#setSize
  96.      * @see      java.awt.Component#getSize
  97.      * @since    JDK1.1
  98.      */
  99.     public Dimension getSize() {
  100.     return new Dimension(width, height);
  101.     }    
  102.  
  103.     /**
  104.      * Set the size of this <code>Dimension</code> object to the specified size.
  105.      * This method is included for completeness, to parallel the
  106.      * <code>setSize</code> method defined by <code>Component</code>.
  107.      * @param    d  the new size for this <code>Dimension</code> object.
  108.      * @see      java.awt.Dimension#getSize
  109.      * @see      java.awt.Component#setSize
  110.      * @since    JDK1.1
  111.      */
  112.     public void setSize(Dimension d) {
  113.     setSize(d.width, d.height);
  114.     }    
  115.  
  116.     /**
  117.      * Set the size of this <code>Dimension</code> object 
  118.      * to the specified width and height.
  119.      * This method is included for completeness, to parallel the
  120.      * <code>setSize</code> method defined by <code>Component</code>.
  121.      * @param    width   the new width for this <code>Dimension</code> object.
  122.      * @param    height  the new height for this <code>Dimension</code> object.
  123.      * @see      java.awt.Dimension#getSize
  124.      * @see      java.awt.Component#setSize
  125.      * @since    JDK1.1
  126.      */
  127.     public void setSize(int width, int height) {
  128.         this.width = width;
  129.         this.height = height;
  130.     }    
  131.  
  132.     /**
  133.      * Checks whether two dimension objects have equal values.
  134.      */
  135.     public boolean equals(Object obj) {
  136.     if (obj instanceof Dimension) {
  137.         Dimension d = (Dimension)obj;
  138.         return (width == d.width) && (height == d.height);
  139.     }
  140.     return false;
  141.     }
  142.  
  143.     /**
  144.      * Returns a string that represents this 
  145.      * <code>Dimension</code> object's values.
  146.      * @return     a string representation of this dimension, 
  147.      *                  including the values of <code>width</code> 
  148.      *                  and <code>height</code>.
  149.      * @since      JDK1.0
  150.      */
  151.     public String toString() {
  152.     return getClass().getName() + "[width=" + width + ",height=" + height + "]";
  153.     }
  154. }
  155.